<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content" style="padding:15px 20px 0px 20px;">
            <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                <div class="form-group">
                    <label class="control-label col-sm-1">柜号:</label>
                    <div class="col-sm-2">
                        <input type="text" id="createPlanNo" name="createPlanNo" class="form-control">
                    </div>
                    <label class="control-label col-sm-1">SKU:</label>
                    <div class="col-sm-2">
                        <input type="text" id="createSku" name="createSku" class="form-control">
                    </div>
                    <label class="control-label col-sm-1">渠道:</label>
                    <div class="col-sm-2">
                        <select  name="orderChannelName" id="orderChannelName" class="form-control">
                            <option value="">请选择渠道</option>
                            <%for(var dict in channel){%>
                            <option value="${dict.channelName}"  >${dict.channelName}</option>
                            <%}%>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-1">大类:</label>
                    <div class="col-sm-2">
                        <select id="productBigClassId" name="productBigClassId"  class="form-control">
                            <option value="">全部分类</option>
                            <%for(var category in category){%>
                            <option value="${category.id}"  >${category.categoryName}</option>
                            <%}%>
                        </select>
                    </div>
                    <label class="control-label col-sm-1">中类:</label>
                    <div class="col-sm-2">
                        <select id="productMidClassId" name="productMidClassId" class="form-control">
                            <option value="">全部分类</option>
                        </select>
                    </div>
                    <label class="control-label col-sm-1">小类:</label>
                    <div class="col-sm-2">
                        <select id="productClassId" name="productClassId" class="form-control">
                            <option value="">全部分类</option>
                        </select>
                    </div>
                    <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                </div>
            </form>
        </div>
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="report-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-check-square-o" aria-hidden="true"></i> 生成质检报告
                </button>
                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>
                <button  class="detail-btn layui-btn  layui-btn-sm layui-btn-warm" style="margin-top: -6px;margin-left: -2px">
                    <i class="fa fa-search" aria-hidden="true"></i> 查看质检数据
                </button>
            </div>
            <!-- START 操作按钮 -->
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/quality/findByQuality.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>


<div id="layer_supplier_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-supplier-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">供应商</label>
                <div class="col-sm-8" style="max-width: 300px;">
                    <select  id="productSupplierId" name="productSupplierId" xm-select="productSupplierId" xm-select-radio xm-select-search>
                        <%for(var dict in supplier){%>
                        <option value="${dict.id}">${dict.supplierName}</option>
                        <%}%>
                    </select>
                    <input type="hidden" name="supplierName" id="supplierName">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">质检数量</label>
                <div class="col-sm-8" style="max-width: 300px;">
                    <input type="text" id="qualityNumber" name="qualityNumber" class="form-control"  />
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">质检结果</label>
                    <div class="col-sm-8" style="max-width: 300px;">
                        <select  id="qualityResult" name="qualityResult" class="form-control" >
                            <option value="">请选择</option>
                            <option value="质检通过">质检通过</option>
                            <option value="质检未通过">质检未通过</option>
                            <option value="二次质检">二次质检</option>
                        </select>
                    </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-produce-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo'}){}%>
<script>
    var $relatedTable = $('#relatedTable');
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '渠道',
                    field: 'createChannelName',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: 'SKU',
                    field: 'createSku',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '产品名称',
                    field: 'productName',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '颜色',
                    field: 'productColorName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '尺寸(CM)',
                    field: 'productCm',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '尺寸(Inch)',
                    field: 'productInch',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '数量',
                    field: 'createNumber',
                    align: 'center',
                    valign: 'middle'
                }

            ],
            onLoadSuccess : function(){

            }
        });

    });

    $("#productBigClassId").change(function () {
        var parentId=$("#productBigClassId").val();
        getCategory(parentId,1);
    });
    $("#productMidClassId").change(function () {
        var parentId=$("#productMidClassId").val();
        getCategory(parentId,2);
    });

    function getCategory(parentId,type) {
        $.ajax({
            url:'/sea/product/category/findByParentId',
            data:{
                id:parentId
            },
            type:'post',
            success:function (data) {
                var list=data;
                if(list.length>0){
                    var category='<option value="">全部分类</option>';
                    for(var i=0;i<list.length;i++){
                        category+='<option value="'+list[i].id+'">'+list[i].categoryName+'</option>';
                    }
                    if(type=='1') {
                        $("#productMidClassId").html(category);
                    }
                    if(type=='2'){
                        $("#productClassId").html(category);
                    }
                }
            }
        });
    }

    // 条件查询
    $('.search-btn').on('click',function () {
        $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/quality/findByQuality.do?'+$('#search-form').serialize() });
    });

    $('.report-btn').on('click',function () {

        var selDatas = $relatedTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var number = 0;
            $.each(selDatas,function(i,d){
                number+=d.createNumber;
            });
            $("#qualityNumber").val(number);
            layer.open({
                type:1,
                title:'生成请购单',
                area:['550px','370px'],
                skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose:false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content:$('#layer_supplier_window')
            })
        }
    });


    $(".save-produce-btn").on('click',function () {
        var supplierName=formSelects.value('productSupplierId', 'nameStr');
        if(supplierName==''){
            parent.layer.msg('请先选择供应商！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        var qualityResult=$("#qualityResult").val();
        if(qualityResult==''){
            parent.layer.msg('请先选择质检状态！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        var selDatas = $relatedTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var ids = [];
            var flag=true;
            $.each(selDatas,function(i,d){
                ids.push(d.id);
            });
            ids = ids.join(',');
            if(flag==true) {
                var inde= layer.load(2, { //icon支持传入0-2
                    shade: [0.1, '#fff'], //0.5透明度的灰色背景
                    content: '正在生成验货报告,请稍后...',
                    success: function (layero) {
                        layero.find('.layui-layer-content').css({
                            'padding-top': '39px',
                            'margin-left': '-50px',
                            'width': '300px',
                            'font-color': 'red',
                            'font-size': '20px'
                        });
                    }
                });
                $.ajax({
                    url: "/sea/supply/quality/save",
                    data: {
                        supplierName:supplierName,
                        qualityResult:$("#qualityResult").val(),
                        qualityNumber:$("#qualityNumber").val(),
                        ids:ids
                    },
                    type: "post",
                    success: function (data) {
                        if(data.ok){
                            layer.msg("生成成功！",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                    $relatedTable.bootstrapTable('refresh');
                                }});
                        }else{
                            layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                }});
                        }
                    },
                });
            }
        }
    })
</script>
</body>
</html>
